﻿Imports DTO
Public Class NgonNguDAO
    Public Shared Function DanhSach_ngonngu_DAO(ByVal strSQL As String) As List(Of NgonNguDTO)
        Dim kq As New List(Of NgonNguDTO)()
        Dim datatable As DataTable = ketnoi.QR_SQL(strSQL)
        Dim ngonngu As NgonNguDTO
        Dim i = 0
        While (i < datatable.Rows.Count)
            ngonngu = New NgonNguDTO
            ngonngu.MaNgonNgu = datatable.Rows(i)("MaNN").ToString
            ngonngu.TenNgonNgu = datatable.Rows(i)("TenNN").ToString
            kq.Add(ngonngu)
            i = i + 1
        End While
        Return kq
    End Function
    Public Shared Function Them_Loai_DAO(ByVal ngonngu As NgonNguDTO) As String
        Dim sql = ""
        If ngonngu.MaNgonNgu = "" Then
            Return "Lỗi: Chưa Nhập Mã Sách"
        End If
        If ngonngu.TenNgonNgu = "" Then
            'sql = "Insert Into LoaiSach(MaLS, TenLS) values('" + loaisach.MaLoaiSach + "',NULL)"
            'Hoặc có thể làm theo dạng:
            sql = String.Format("Insert Into NgonNgu(MaNN,TenNN) values('{0}',NULL)", ngonngu.MaNgonNgu)
        Else
            sql = String.Format("Insert Into NgonNgu(MaNN,TenNN) values('{0}',N'{1}')", ngonngu.MaNgonNgu, ngonngu.TenNgonNgu)
        End If
        Return ketnoi.NonQR_SQL(sql)
    End Function
    Public Shared Function Sua_Loai_DAO(ByVal ngonngu As NgonNguDTO, ByVal MaCu As String) As String
        Dim sql = ""
        If ngonngu.MaNgonNgu = "" Then
            Return "Lỗi: Chưa Nhập Mã Sách"
        End If
        If ngonngu.TenNgonNgu = "" Then
            sql = String.Format("Update NgonNgu set MaNN='{0}', TenNN=NULL where MaNN='{1}'", ngonngu.MaNgonNgu, MaCu)
        Else
            sql = String.Format("Update NgonNgu set MaNN='{0}', TenNN=N'{1}' where MaNN='{2}'", ngonngu.MaNgonNgu, ngonngu.TenNgonNgu, MaCu)
        End If
        Return ketnoi.NonQR_SQL(sql)
    End Function
    Public Shared Function Xoa_Loai_DAO(ByVal ngonngu As NgonNguDTO) As String
        Dim sql = "Delete From NgonNgu where MaNN='" + ngonngu.MaNgonNgu + "'"
        Return ketnoi.NonQR_SQL(sql)
    End Function
End Class
